package com.htht.smartschool.action.tclass;

import java.util.List;
import java.util.Map;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.teacher.TClass;
import com.htht.smartschool.service.tclass.TclassService;
import com.htht.smartschool.util.system.GsonUtils;

public class TclassAction extends BaseAction {

	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		boolean flag = false;
		TclassService tclassService = new TclassService();
		TClass tclass = (TClass) GsonUtils.getInstance().fromJson(pd.getData(), TClass.class);
		if(pd.getCmd().equalsIgnoreCase("getAllClassByPagesize")){
			@SuppressWarnings("rawtypes")
			Map map = tclassService.getAllClassByPagesize(tclass);
			if(map != null){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getGradeAndClass")){
			List<TClass> tc = tclassService.getGradeAndClass(tclass);
			if(tc != null){
				flag = true;
				obj.setData(tc);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("addClass")){
			boolean result = tclassService.addClass(tclass);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("添加失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteClasses")){
			@SuppressWarnings("rawtypes")
			Map map = tclassService.deleteClasses(tclass.getClasscode());
			flag = true;
			obj.setData(map);
		}else if(pd.getCmd().equalsIgnoreCase("updateClass")){
			Map map = tclassService.updateClass(tclass);
			if(map.size() > 0){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("修改失败！");
			}
		}
		return flag;
	}

}
